﻿using System.Threading;
using ET;
using UnityGameFramework.Runtime;

namespace StarForce
{
    public class ETComponent : GameFrameworkComponent
    {
        private void Start()
        {
            SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
            ET.Game.Options = new Options();
            ET.Game.EventSystem.Add(typeof(ET.Game).Assembly);
            
            ET.Game.Scene.AddComponent<ET.TimerComponent>();
            ET.Game.Scene.AddComponent<CoroutineLockComponent>();
        }

        private void Update()
        {
            ThreadSynchronizationContext.Instance.Update();
            ET.Game.EventSystem.Update();
        }

        private void LateUpdate()
        {
            ET.Game.EventSystem.LateUpdate();
        }
        
        public void OnApplicationQuit()
        {
            ET.Game.Close();
        }
    }
}